package com.zwl.sjzmanagement.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zwl.model.Atlas;
import com.zwl.model.RoomCard;
import com.zwl.model.RoomContainers;
import com.zwl.vo.RoomCardContainersVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoomCardMapper extends BaseMapper<RoomCardContainersVo> {

    @Select("select * from room_cards where map_name = #{altaName}")
    List<RoomCard> queryRoomCardList(@Param("altaName") String altaName);

    @Select("select * from map")
    List<Atlas> queryMapList();

    @Select("select * from room_containers where room_name=#{roomName}")
    List<RoomContainers> queryRoomToContainers(@Param("roomName") String roomName);

    @Update("UPDATE room_cards " +
            "SET card_image = #{roomCard.cardImage}, " +
            "map_name = #{roomCard.mapName}, " +
            "room_name = #{roomCard.roomName}, " +
            "usage_location = #{roomCard.usageLocation}, " +
            "key_card_value = #{roomCard.keyCardValue}, " +
            "single_door_open_cost = #{roomCard.singleDoorOpenCost}, " +
            "updated_at = NOW() " +
            "WHERE id = #{roomCard.id}")
    void updateRoomCard(@Param("roomCard") RoomCard roomCard);

    @Insert("INSERT INTO room_cards " +
            "(card_image, map_name, room_name, usage_location, key_card_value, single_door_open_cost, created_at, updated_at) " +
            "VALUES " +
            "(#{roomCard.cardImage}, #{roomCard.mapName}, #{roomCard.roomName}, #{roomCard.usageLocation}, " +
            "#{roomCard.keyCardValue}, #{roomCard.singleDoorOpenCost}, NOW(), NOW())")
    void addRoomCard(@Param("roomCard") RoomCard roomCard);

    @Update("UPDATE room_containers " +
            "SET room_name = #{newRoomContainers.roomName}, " +
            "container_image = #{newRoomContainers.containerImage}, " +
            "container_info = #{newRoomContainers.containerInfo} " +
            "WHERE id = #{newRoomContainers.id}")
    void updateRoomContainers(@Param("newRoomContainers") RoomContainers newRoomContainers);

    @Insert("INSERT INTO room_containers " +
            "(room_name, container_image, container_info) " +
            "VALUES " +
            "(#{newRoomContainers.roomName}, #{newRoomContainers.containerImage}, #{newRoomContainers.containerInfo})")
    void addRoomContainers(@Param("newRoomContainers") RoomContainers newRoomContainers);


    @Delete("delete from room_cards where id=#{id}")
    void deleteRoomCardById(@Param("id") Integer id);


    @Select("select * from room_cards where id = #{id}")
    RoomCard queryById(@Param("id")  Integer id);

    @Delete("delete from room_containers where room_name=#{roomName}")
    void deleteRoomContainersByName(@Param("roomName") String roomName);
}
